package io.renren.modules.lanling.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.renren.modules.lanling.entity.SchoolEvaluateEntity;
import io.renren.modules.lanling.service.SchoolEvaluateService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 学校评价表
 *
 * @author LANLING
 * @email lanling@gmail.com
 * @date 2018-11-30 10:34:41
 */
@RestController
@RequestMapping("lanling/schoolevaluate")
public class SchoolEvaluateController {

    private static final Logger logger = LoggerFactory.getLogger(SchoolEvaluateController.class);

    @Autowired
    private SchoolEvaluateService schoolEvaluateService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("lanling:schoolevaluate:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = schoolEvaluateService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lanling:schoolevaluate:info")
    public R info(@PathVariable("id") Integer id) {
        SchoolEvaluateEntity schoolEvaluate = schoolEvaluateService.queryObject(id);

        return R.ok().put("schoolEvaluate", schoolEvaluate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("lanling:schoolevaluate:save")
    public R save(@RequestBody SchoolEvaluateEntity schoolEvaluate) {
        schoolEvaluate.setStudentId(16);
        schoolEvaluate.setStudentName("管理员");
        schoolEvaluate.setCreateDate(new Date());
        schoolEvaluateService.insert(schoolEvaluate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("lanling:schoolevaluate:update")
    public R update(@RequestBody SchoolEvaluateEntity schoolEvaluate) {
        ValidatorUtils.validateEntity(schoolEvaluate);
        schoolEvaluateService.update(schoolEvaluate);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("lanling:schoolevaluate:delete")
    public R delete(@RequestBody Integer[] ids) {
        schoolEvaluateService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
